Skip to content

Look a worker's modules up once per session - #88

Merged
HalRiveria-Bot merged 2 commits into
mainfrom
fix/cache-module-lookup
Nov 30, 2026
Merged

HalRiveria-Bot merged 2 commits into
mainfrom
fix/cache-module-lookup

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

The worker-safety check asks Get-Module -ListAvailable whether a worker can load each module its commands come from, on every Invoke-PkRunspaceJobs call. On Windows PowerShell 5.1 that searches all of PSModulePath each time, so a script that calls the engine once per folder pays for it every time.

  • The answer is kept for the session, per module name and PSModulePath ([PkState]::ModuleFound, a concurrent dictionary).
  • A module the kit didn't find, and that's installed afterwards, is missed until a new window. One put on $env:PSModulePath, as the finding's message suggests, is looked up again. The README says so.

Tested

New harness section BK counts the lookups with a stand-in Get-Module inside the kit, with one module on PSModulePath and one imported by path.

  • Before (5.1 and 7): three checks did 3 lookups, two runs after them 2 more, and two checks of the unloadable module 2; 3 of the section's 4 assertions failed. The fourth (a module put on PSModulePath later is found) guards the cache, and passes before and after.
  • After: one lookup each, and all pass.
  • On 5.1 with 154 modules installed, a one-job run whose worker calls Get-FileHash went from 47 ms to 23 ms (average of 20).
  • Full harness: ALL PASSED (667 assertions, none skipped) on Windows PowerShell 5.1, then PowerShell 7, in fresh processes.

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 30, 2026 15:07
The worker-safety check asked Get-Module -ListAvailable about each module a
worker's commands come from, on every Invoke-PkRunspaceJobs call. On Windows
PowerShell 5.1 each lookup searches all of PSModulePath. The answer is now
kept per module name and PSModulePath.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit 58eaa4a into main Nov 30, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/cache-module-lookup branch November 30, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants